package com.itheima.test;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

public class MyJFrame extends JFrame implements ActionListener {
    JButton jbtn1 = new JButton("btn1");
    JButton jbtn2 = new JButton("btn2");

    public MyJFrame(){
        this.setSize(603, 680);
        //设置界面标题
        this.setTitle("拼图单机版 V1.0");
        //设置窗口置顶
        this.setAlwaysOnTop(true);
        this.setLocationRelativeTo(null);
        //设置默认关闭模式
        this.setDefaultCloseOperation(3);
        //取消默认的居中对齐的布局方式
        this.setLayout(null);

        jbtn1.setBounds(0, 0, 100, 50);
        jbtn1.addActionListener(this);

        jbtn2.setBounds(100, 0, 100, 50);
        jbtn2.addActionListener(this);
        this.add(jbtn1);
        this.add(jbtn2);

        this.setVisible(true);

    }
    @Override
    public void actionPerformed(ActionEvent e){
        //对当前点击的按钮进行判断
        Object source = e.getSource();
        if ( source == jbtn1 ){
            jbtn1.setSize(200, 200);
        } else if ( source == jbtn2 ){
            Random r = new Random();
            jbtn2.setLocation(r.nextInt(500), r.nextInt(500));
        }
    }
}
